package likou;

/**
 * @author: 唐小尊
 * @email: 1171702529@qq.com
 * @cate: 2021/03/18 19:40
 */
public class _92 {
    static class ListNode {
        int val;
        ListNode next;

        ListNode() {
        }

        ListNode(int val) {
            this.val = val;
        }

        ListNode(int val, ListNode next) {
            this.val = val;
            this.next = next;
        }
    }

    public static void main(String[] args) {
        ListNode head = new ListNode(1);
        ListNode deep = head;
        deep.next = new ListNode(2);
        deep.next.next = new ListNode(3);
        deep.next.next.next = new ListNode(4);
        deep.next.next.next.next = new ListNode(5);
        reverseLinkedList(head);
        while (head!=null){
            System.out.println(head.val);
            head = head.next;
        }
    }

    //反转一个链表
    private static void reverseLinkedList(ListNode head) {
        ListNode pre = null;
        ListNode cur = head;

        while (cur != null) {
            ListNode next = cur.next;
            cur.next = pre;
            pre = cur;
            cur = next;
        }
    }
}
